package com.linkage.educloud.ah.bean;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by Mr'Tang on 2018/9/17.
 */

public class DynamicBean implements Serializable {
    private String dynamic_id;
    private String avatar;
    private String name;
    private String userid;
    private int role;
    private String time;
    private String content;
    private int content_type;
    private int type;
    private String classId;
    private String theme;
    private int praisednum;
    private int commentnum;
    private int ispriased;
    private List<DynamicPriasedBean> priasedList;
    private List<DynamicCommentBean> commentList;
    private List<DynamicImageBean> imageList;

    public static List<DynamicBean> fromJsonObject(JSONArray array) {
        List<DynamicBean> list = new ArrayList<>();
        for (int a = 0; a < array.length(); a++) {
            DynamicBean dic = new DynamicBean();
            try {
                JSONObject json = array.getJSONObject(a);
                dic.dynamic_id = json.getString("dynamic_id");
                dic.avatar = json.getString("avatar");
                dic.name = json.getString("name");
                dic.userid = json.getString("userid");
                dic.role = json.getInt("role");
                dic.time = json.getString("time");
                dic.classId = json.getString("classId");
                dic.content = json.getString("content");
                dic.content_type = json.getInt("content_type");
                dic.type = json.getInt("type");
                dic.praisednum = json.getInt("praisednum");
                dic.commentnum = json.getInt("commentnum");
                dic.ispriased = json.getInt("ispriased");
                if (json.has("imagelist")) {
                    JSONArray ja = json.getJSONArray("imagelist");
                    List<DynamicImageBean> imglist = new ArrayList<DynamicImageBean>();
                    for (int i = 0; i < ja.length(); i++) {
                        JSONObject obj = ja.getJSONObject(i);
                        DynamicImageBean img = DynamicImageBean.fromJsonObject(obj);
                        img.setType(dic.getType());
                        imglist.add(img);
                    }
                    dic.setImageList(imglist);
                }
                if (json.has("praisedlist")) {
                    JSONArray ja = json.getJSONArray("praisedlist");
                    List<DynamicPriasedBean> priaselist = new ArrayList<DynamicPriasedBean>();
                    for (int i = 0; i < ja.length(); i++) {
                        JSONObject obj = ja.getJSONObject(i);
                        DynamicPriasedBean priased = DynamicPriasedBean.fromJsonObject(obj);
                        priaselist.add(priased);
                    }
                    dic.setPriasedList(priaselist);
                }
                if (json.has("commentlist")) {
                    JSONArray ja = json.getJSONArray("commentlist");
                    List<DynamicCommentBean> commentlist = new ArrayList<DynamicCommentBean>();
                    for (int i = 0; i < ja.length(); i++) {
                        JSONObject obj = ja.getJSONObject(i);
                        DynamicCommentBean comment = DynamicCommentBean.fromJsonObject(obj);
                        commentlist.add(comment);
                    }
                    dic.setCommentList(commentlist);
                }
                list.add(dic);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return list;
    }

    public String getDynamic_id() {
        return dynamic_id;
    }

    public void setDynamic_id(String dynamic_id) {
        this.dynamic_id = dynamic_id;
    }

    public String getAvatar() {
        return avatar;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getUserid() {
        return userid;
    }

    public void setUserid(String userid) {
        this.userid = userid;
    }

    public int getRole() {
        return role;
    }

    public void setRole(int role) {
        this.role = role;
    }

    public String getTime() {
        return time;
    }

    public void setTime(String time) {
        this.time = time;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public int getContent_type() {
        return content_type;
    }

    public void setContent_type(int content_type) {
        this.content_type = content_type;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public String getTheme() {
        return theme;
    }

    public void setTheme(String theme) {
        this.theme = theme;
    }

    public int getPraisednum() {
        return praisednum;
    }

    public void setPraisednum(int praisednum) {
        this.praisednum = praisednum;
    }

    public int getCommentnum() {
        return commentnum;
    }

    public void setCommentnum(int commentnum) {
        this.commentnum = commentnum;
    }

    public int getIspriased() {
        return ispriased;
    }

    public void setIspriased(int ispriased) {
        this.ispriased = ispriased;
    }

    public String getClassId() {
        return classId;
    }

    public void setClassId(String classId) {
        this.classId = classId;
    }


    public List<DynamicPriasedBean> getPriasedList() {
        return priasedList == null ? new ArrayList<DynamicPriasedBean>() : priasedList;
    }

    public void setPriasedList(List<DynamicPriasedBean> priasedList) {
        this.priasedList = priasedList;
    }

    public List<DynamicCommentBean> getCommentList() {
        return commentList == null ? new ArrayList<DynamicCommentBean>() : commentList;
    }

    public void setCommentList(List<DynamicCommentBean> commentList) {
        this.commentList = commentList;
    }

    public List<DynamicImageBean> getImageList() {
        return imageList == null ? new ArrayList<DynamicImageBean>() : imageList;
    }

    public void setImageList(List<DynamicImageBean> imageList) {
        this.imageList = imageList;
    }

}
